#!/bin/bash

git pull
go install tms-server/tms-webhook


portParam=9021

echo "stop tms-webhook"

tmsPID=`sudo netstat -nplt | grep tms | grep ${portParam} | awk '{print $7}' | awk -F / '{print $1}'`
echo "old webhook_pid: ${tmsPID}"
if [ ${tmsPID} ]
then
	echo "kill webhook_pid ${tmsPID}"
	kill -9 ${tmsPID}
fi


echo "starting tms-webhook"
logDir=${GOPATH}/src/tms-server/logs
if [ ! -d ${logDir} ]; then
  mkdir -p ${logDir}
fi
nohup ${GOPATH}/bin/tms-webhook >${logDir}/webhook.log 2>&1 &
